<template>
  <div class="navMenu">
    <div class="left">
      <el-row class="tac">
        <el-col :span="12">
          <el-menu
            unique-opened
            class="el-menu-vertical-demo"
            @open="handleOpen"
            @close="handleClose"
            router
          >
            <el-submenu
              :index="item.mid + ''"
              v-for="item in mainMenu"
              :key="item.mid"
            >
              <template slot="title">
                <span>{{ item.mname }}</span>
              </template>
              <el-menu-item-group v-for="item in subMenu" :key="item.mid">
                <el-menu-item :index="item.url">{{ item.mname }}</el-menu-item>
              </el-menu-item-group>
            </el-submenu>
          </el-menu>
        </el-col>
      </el-row>
    </div>
    <div class="right">
      <router-view />
    </div>
  </div>
</template>

<script>
import api from "../api";
export default {
  name: "NavMenu",
  data() {
    return {
      mainMenu: [],
      subMenu: [],
    };
  },
  mounted() {
    api
      .getMenu({
        pid: 0,
      })
      .then((res) => {
        if (res.status == 200) {
          this.mainMenu = res.data;
        }
      });
  },
  methods: {
    handleOpen(key, keyPath) {
      this.http(key);
      // console.log(key, keyPath);
    },
    handleClose(key, keyPath) {
      // console.log(key, keyPath);
    },
    http(num) {
      api
        .getMenu({
          pid: num,
        })
        .then((res) => {
          if (res.status == 200) {
            this.subMenu = res.data;
          }
        });
    },
  },
};
</script>

<style lang="less" scoped>
.navMenu {
  display: flex;
  margin-top: 10px;

  .left {
    width: 300px;
    text-align: left;

    ul {
      border: 0px;
    }
  }

  .right {
    width: 100%;
    background-color: #fff;
  }
}
.el-col {
  width: 300px;
}
</style>